package com.loongtech.bi.manager.realTime;

import com.loongtech.bi.action.PageHelper;
import com.loongtech.bi.action.UIHelper;
import com.loongtech.bi.entity.realTime.EntityDauByQuantum;
import com.loongtech.bi.entity.realTime.EntityNewUserByQuantum;
import com.loongtech.bi.entity.realTime.EntityOnlineByQuantum;
import com.loongtech.bi.entity.realTime.EntityRealTimePcu;
import com.loongtech.bi.manager.player.PcuManager;
import com.loongtech.bi.manager.system.BiPlatformManager;
import com.loongtech.bi.manager.system.ConfigManager;
import com.loongtech.bi.support.chart.ChartData1;
import com.loongtech.bi.support.chart.ChartFlow;
import com.loongtech.bi.support.chart.ChartSelect;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import com.loongtech.core.util.Time;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.Map.Entry;

/**
 * 实时数据-分服概况manager
 * 
 * @author marin
 * @date 2015-09-15
 */
@Service
public class ServerRealTimeManager extends ManagerQueryCacheBase<Object> {
	private static final long serialVersionUID = 1L;
	
	@Autowired
	OnlineByQuantumManager onlineByQuantumManager;
	@Autowired
	RealTimePcuManager realTimePcuManager;
	@Autowired
	NewUserByQuantumManager newUserByQuantumManager;
	@Autowired
	NewUserByDayManager newUserByDayManager;
    @Autowired
    DistinctNewUserByDayManager distinctNewUserByDayManager;
	@Autowired
	DauByQuantumManager dauByQuantumManager;
	@Autowired
	DauByDayManager dauByDayManager;
	@Autowired
	RealTimeAcuManager realTimeAcuManager;
	@Autowired
	PcuManager pcuManager;
    @Autowired
    ConfigManager configManager;
    @Autowired
    AddCashUserByDayManager addCashUserByDayManager;
    @Autowired
    CashAddByDayManager cashAddByDayManager;
    @Autowired
    UserSecondLeftByDayManager userSecondLeftByDayManager;

    public List<OnlineRealTimeData> getOnlineRealTimeDatas(Date lookDate, Date compareDate, Date lastWeekDate, String queryPlatform, String queryChannel, String queryServer) {
        List<EntityOnlineByQuantum> tmp = onlineByQuantumManager.getOnlineRealTimeDatas(lookDate, compareDate, lastWeekDate, queryPlatform, queryChannel, queryServer);

        if (tmp == null || tmp.size() <= 0) {
            return null;
        }

        String conf = configManager.getConfigValueByName(ConfigManager.ONLINE_RADIO);
        Map<String, OnlineRealTimeData> map = new LinkedHashMap<>();
        for (EntityOnlineByQuantum e : tmp) {
            String quantum = e.getQuantum();
            if ("00:00".equals(quantum) || "23:59".equals(quantum)) {
                continue;
            }

            String dateStr = Time.getDateStr(e.getDay());
            String minuteStr = doQuantum(quantum, conf);

            OnlineRealTimeData t = map.get(dateStr + "-" + minuteStr);
            if (t == null) {
                t = new OnlineRealTimeData();
                map.put(dateStr + "-" + minuteStr, t);
            }
            t.setDateStr(dateStr);
            t.setMinuteStr(minuteStr);
            t.setOnline(e.getOnlinenum() > t.getOnline() ? e.getOnlinenum() : t.getOnline());
        }

        List<OnlineRealTimeData> result = new ArrayList<>(map.values());
        Collections.sort(result, new OnlineRealTimeData().comparator);

        return result;
    }

    // 处理时间字符串，当在线日志不是5分钟记一次的话，需要对齐
    private String doQuantum(String quantum, String conf) {
        if (conf != null && !"5".equals(conf) && quantum.endsWith("5")) {
            return quantum.substring(0, quantum.length() - 1) + "0";
        } else {
            return quantum;
        }
    }

    public List<OnlineRealTimeData> getOnlineRealTimeDatas(Date lookDate, Date compareDate) {
        List<EntityOnlineByQuantum> tmp = onlineByQuantumManager.getOnlineRealTimeDatas(lookDate, compareDate);
        if (tmp == null || tmp.size() <= 0) {
            return null;
        }

        String conf = configManager.getConfigValueByName(ConfigManager.ONLINE_RADIO);

        List<OnlineRealTimeData> result = new ArrayList<>();
        for (EntityOnlineByQuantum e : tmp) {
            OnlineRealTimeData t = new OnlineRealTimeData();
            t.setDateStr(Time.getDateStr(e.getDay()));
            t.setMinuteStr(doQuantum(e.getQuantum(), conf));
            t.setOnline(e.getOnlinenum());

            result.add(t);
        }
        Collections.sort(result, new OnlineRealTimeData().comparator);

        return result;
    }

	/**
	 * 得到项目整体实时在线数据
	 * @param lookDate
	 * @return
	 */
	public List<OnlineRealTimeData> getOnlineRealTimeDatas(Date lookDate) {
		List<EntityOnlineByQuantum> tmp = onlineByQuantumManager.getOnlineRealTimeDatas(lookDate, new Date(lookDate.getTime() - Time.DAY));
		if (tmp == null || tmp.size() <= 0) {
			return null;
		}

        String conf = configManager.getConfigValueByName(ConfigManager.ONLINE_RADIO);
		
		List<OnlineRealTimeData> result = new ArrayList<>();
		for (EntityOnlineByQuantum e : tmp) {
			OnlineRealTimeData t = new OnlineRealTimeData();
			t.setDateStr(Time.getDateStr(e.getDay()));
			t.setMinuteStr(doQuantum(e.getQuantum(), conf));
			t.setOnline(e.getOnlinenum());
			
			result.add(t);
		}
		Collections.sort(result, new OnlineRealTimeData().comparator);
		
		// 前一天的
		/*List<EntityOnlineByQuantum> tmp1 = onlineByQuantumManager.getOnlineRealTimeDatas(new Date(lookDate.getTime() - Time.DAY));
		if (tmp1 != null && tmp1.size() > 0) {
			List<OnlineRealTimeData> result1 = new ArrayList<>();
			for (EntityOnlineByQuantum e : tmp1) {
				OnlineRealTimeData t = new OnlineRealTimeData();
				t.setDateStr(Time.getDateStr(e.getDay()));
				t.setMinuteStr(e.getQuantum());
				t.setOnline(e.getOnlinenum());
				
				result1.add(t);
			}
			Collections.sort(result1, new OnlineRealTimeData().comparator);
			result.addAll(result1);
		}*/
		
		
		return result;
	}
	
	// 分服实时数据
	public List<ServerRealTimeData> getServerRealTimeDatas(Date lookDate, List<String> serverids) {
		Map<String, ServerRealTimeData> result = new HashMap<>(); // serverid-minuteStr=ServerRealTimeData

        String conf = configManager.getConfigValueByName(ConfigManager.ONLINE_RADIO);

		// online
		List<EntityOnlineByQuantum> tmp1 = onlineByQuantumManager.getOnlineRealTimeDatasByServers(lookDate, serverids);
		if (tmp1 != null) {
			for (EntityOnlineByQuantum e : tmp1) {
                String key = e.getServerid() + "-" + doQuantum(e.getQuantum(), conf);
				ServerRealTimeData t = result.get(key);
				if (t == null) {
					t = new ServerRealTimeData();
					t.setServerid(e.getServerid());
					t.setMinuteStr(doQuantum(e.getQuantum(), conf));
					result.put(key, t);
				}
				t.setOnline(e.getOnlinenum());
			}
		}

		// newUser
		List<EntityNewUserByQuantum> tmp2 = newUserByQuantumManager.getNewUserRealTimeDatasByServers(lookDate, serverids);
		if (tmp2 != null) {
			for (EntityNewUserByQuantum e : tmp2) {
				String key = e.getServerid() + "-" + doQuantum(e.getQuantum(), conf);
				ServerRealTimeData t = result.get(key);
				if (t == null) {
					t = new ServerRealTimeData();
					t.setServerid(e.getServerid());
					t.setMinuteStr(doQuantum(e.getQuantum(), conf));
					result.put(key, t);
				}
				t.setNewUser(e.getNew_user());
			}
		}
		
		// activeUser
		List<EntityDauByQuantum> tmp3 = dauByQuantumManager.getDauRealTimeDatasByServers(lookDate, serverids);
		if (tmp3 != null) {
			for (EntityDauByQuantum e : tmp3) {
				String key = e.getServerid() + "-" + doQuantum(e.getQuantum(), conf);
				ServerRealTimeData t = result.get(key);
				if (t == null) {
					t = new ServerRealTimeData();
					t.setServerid(e.getServerid());
					t.setMinuteStr(doQuantum(e.getQuantum(), conf));
					result.put(key, t);
				}
				t.setActiveUser(e.getDau());
			}
		}

		// 处理在线两点数据不协调问题
        for (Entry<String, ServerRealTimeData> entry : result.entrySet()) {
            ServerRealTimeData t = entry.getValue();
            if ("00:00".equals(t.getMinuteStr())) {
                ServerRealTimeData t1 = result.get(t.getServerid() + "-00:05");
                if (t1 != null) {
                    t.setOnline(t1.getOnline());
                }
            }
            if ("23:59".equals(t.getMinuteStr())) {
                ServerRealTimeData t1 = result.get(t.getServerid() + "-23:55");
                if (t1 != null) {
                    t.setOnline(t1.getOnline());
                }
            }
        }

		List<ServerRealTimeData> t = new ArrayList<ServerRealTimeData>(result.values());
		Collections.sort(t, new ServerRealTimeData().comparator);
		return t;
	}
	
	/**
	 * 服务器容量数据
	 * @param lookDate
	 * @return
	 */
	public List<ServerCapacityData> getServerCapacityDatas(Date lookDate, List<String> serverids) {
		List<EntityRealTimePcu> tmp = realTimePcuManager.getPcuRealTimeDatas(lookDate, serverids);
		if (tmp == null || tmp.size() <= 0) {
			return null;
		}
		
		List<ServerCapacityData> result = new ArrayList<>();
		for (EntityRealTimePcu e : tmp) {
			ServerCapacityData s = new ServerCapacityData();
			s.setDateStr(Time.getDateStr(e.getDay()));
			s.setServerid(e.getServerid());
			s.setCapacityUsedRadio(BiPlatformManager.getServerCapacityById(e.getServerid()) == 0 ? 0 : PageHelper.floatKeepTwoNumber((e.getPcu() * 1.0 / BiPlatformManager.getServerCapacityById(e.getServerid()))));
			result.add(s);
		}
		Collections.sort(result, new ServerCapacityData().comparatorDate);
		
		return result;
	}
	
	/**
	 * 服务器详细数据
	 * @param lookDate
	 */
	public void updateServerRealTimeDetailData(Date lookDate, List<ServerRealTimeDetailData> serverRealTimeDetailDatas, ServerRealTimeDetailData allSumServerRealTimeDetailData) {
		Map<String, ServerRealTimeDetailData> result = new HashMap<>(); // serverid=ServerRealTimeDetailData
		
		// 实时在线人数
		List<Object[]> tmp1 = onlineByQuantumManager.getAllOnlineRealTimeDatas(lookDate);
		if (tmp1 != null && tmp1.size() > 0 && tmp1.get(0) != null) {
			for (Object[] e : tmp1) {
				String serverid = e[0].toString();
				long onlinenum = Long.parseLong(e[1].toString());
				ServerRealTimeDetailData t = result.get(serverid);
				if (t == null) {
					t = new ServerRealTimeDetailData();
					t.setServerid(serverid);
					result.put(serverid, t);
				}
				t.setOnlinenum(onlinenum);
			}
		}
		
		// 实时PCU
		List<Object[]> tmp2 = realTimePcuManager.getAllPcuRealTimeDatas(lookDate);
		if (tmp2 != null && tmp2.size() > 0 && tmp2.get(0) != null) {
			for (Object[] e : tmp2) {
				String serverid = e[0].toString();
				long pcu = Long.parseLong(e[1].toString());
				ServerRealTimeDetailData t = result.get(serverid);
				if (t == null) {
					t = new ServerRealTimeDetailData();
					t.setServerid(serverid);
					result.put(serverid, t);
				}
				t.setPcu(pcu);
			}
		}

		// 实时ACU
		List<Object[]> tmp3 = realTimeAcuManager.getAllAcuRealTimeDatas(lookDate);
		if (tmp3 != null && tmp3.size() > 0 && tmp3.get(0) != null) {
			for (Object[] e : tmp3) {
				String serverid = e[0].toString();
				long acu = Long.parseLong(e[1].toString());
				ServerRealTimeDetailData t = result.get(serverid);
				if (t == null) {
					t = new ServerRealTimeDetailData();
					t.setServerid(serverid);
					result.put(serverid, t);
				}
				t.setAcu(acu);
			}
		}
		
		// 实时新增
		List<Object[]> tmp4 = newUserByDayManager.getAllNewUserRealTimeDatas(lookDate);
		if (tmp4 != null && tmp4.size() > 0 && tmp4.get(0) != null) {
			for (Object[] e : tmp4) {
				String serverid = e[0].toString();
				int newUser = Integer.parseInt(e[1].toString());
				ServerRealTimeDetailData t = result.get(serverid);
				if (t == null) {
					t = new ServerRealTimeDetailData();
					t.setServerid(serverid);
					result.put(serverid, t);
				}
				t.setNewUser(newUser);
			}
		}

        // 去重新增帐号
        List<Object[]> tmp40 = distinctNewUserByDayManager.getAllDistinctNewUserRealTimeDatas(lookDate);
        if (tmp40 != null && tmp40.size() > 0 && tmp40.get(0) != null) {
            for (Object[] e : tmp40) {
                String serverid = e[0].toString();
                int newUser = Integer.parseInt(e[1].toString());
                ServerRealTimeDetailData t = result.get(serverid);
                if (t == null) {
                    t = new ServerRealTimeDetailData();
                    t.setServerid(serverid);
                    result.put(serverid, t);
                }

                t.setDistinctNewUser(newUser);
            }
        }
		
		// 实时活跃
		List<Object[]> tmp5 = dauByDayManager.getAllDauRealTimeDatas(lookDate);
		if (tmp5 != null && tmp5.size() > 0 && tmp5.get(0) != null) {
			for (Object[] e : tmp5) {
				String serverid = e[0].toString();
				int dau = Integer.parseInt(e[1].toString());
				ServerRealTimeDetailData t = result.get(serverid);
				if (t == null) {
					t = new ServerRealTimeDetailData();
					t.setServerid(serverid);
					result.put(serverid, t);
				}
				t.setAcitveUser(dau);
			}
		}
		
		// 昨日PCU
		Date yesterday = new Date(lookDate.getTime() - Time.DAY);
		List<Object[]> tmp6 = pcuManager.getPcuGroupByServer(yesterday, yesterday);
		if (tmp6 != null && tmp6.size() > 0 && tmp6.get(0) != null) {
			for (Object[] e : tmp6) {
				String serverid = e[0].toString();
				long pcu = Long.parseLong(e[1].toString());
				ServerRealTimeDetailData t = result.get(serverid);
				if (t == null) {
					t = new ServerRealTimeDetailData();
					t.setServerid(serverid);
					result.put(serverid, t);
				}
				t.setPcuYesterday(pcu);
			}
		}

        // 付费账号数
        List<Object[]> tmpn1 = addCashUserByDayManager.getServerPayUserRealTimeDatas(lookDate);
        if (tmpn1 != null && tmpn1.size() > 0 && tmpn1.get(0) != null) {
            for (Object[] e : tmpn1) {
                String serverid = e[0].toString();
                long cashuser = Long.parseLong(e[1].toString());
                ServerRealTimeDetailData t = result.get(serverid);
                if (t == null) {
                    t = new ServerRealTimeDetailData();
                    t.setServerid(serverid);
                    result.put(serverid, t);
                }
                t.setCashUser(cashuser);
            }
        }

        // 付费金额
        List<Object[]> tmpn2 = cashAddByDayManager.getServerPayRealTimeDatas(lookDate);
        if (tmpn2 != null && tmpn2.size() > 0 && tmpn2.get(0) != null) {
            for (Object[] e : tmpn2) {
                String serverid = e[0].toString();
                long cash = Long.parseLong(e[1].toString());
                ServerRealTimeDetailData t = result.get(serverid);
                if (t == null) {
                    t = new ServerRealTimeDetailData();
                    t.setServerid(serverid);
                    result.put(serverid, t);
                }
                t.setCash(UIHelper.getYuan(cash));
            }
        }

        // 昨日新增账号次留
        List<Object[]> tmpn3 = userSecondLeftByDayManager.getServer2LeftRealTimeDatas(yesterday);
        if (tmpn3 != null && tmpn3.size() > 0 && tmpn3.get(0) != null) {
            for (Object[] e : tmpn3) {
                String serverid = e[0].toString();
                float the2Left = Float.parseFloat(e[1].toString());
                ServerRealTimeDetailData t = result.get(serverid);
                if (t == null) {
                    t = new ServerRealTimeDetailData();
                    t.setServerid(serverid);
                    result.put(serverid, t);
                }
                t.setThe2Left(the2Left);
            }
        }

        // 昨日新增设备次留
        List<Object[]> tmpn4 = userSecondLeftByDayManager.getServer2LeftRealTimeMacDatas(yesterday);
        if (tmpn4 != null && tmpn4.size() > 0 && tmpn4.get(0) != null) {
            for (Object[] e : tmpn4) {
                String serverid = e[0].toString();
                float the2Left = Float.parseFloat(e[1].toString());
                ServerRealTimeDetailData t = result.get(serverid);
                if (t == null) {
                    t = new ServerRealTimeDetailData();
                    t.setServerid(serverid);
                    result.put(serverid, t);
                }
                t.setMac2Left(the2Left);
            }
        }

		// 服务器容量，使用率，昨日最高使用率，活跃付费率
		for (Entry<String, ServerRealTimeDetailData> entry : result.entrySet()) {
			String k = entry.getKey();
			ServerRealTimeDetailData v = entry.getValue();

            v.setCapacity(BiPlatformManager.getServerCapacityById(k));
			v.setCapacityUsedRadio(v.getCapacity() == 0 ? 0 : (float)(v.getOnlinenum() * 1.0 / v.getCapacity()));
			v.setMaxCapacityUsedRadioYesterday(v.getCapacity() == 0 ? 0 : (float)(v.getPcuYesterday() * 1.0 / v.getCapacity()));
			v.setActiveUserPayRadio(v.getAcitveUser() == 0 ? 0 : (float)(v.getCashUser() * 1.0 / v.getAcitveUser()));
		}
		
		List<ServerRealTimeDetailData> t = new ArrayList<>(result.values());
		Collections.sort(t, new ServerRealTimeDetailData().comparatorOnline);
		serverRealTimeDetailDatas.addAll(t);
		
		for (ServerRealTimeDetailData s : t) {
			allSumServerRealTimeDetailData.setOnlinenum(allSumServerRealTimeDetailData.getOnlinenum() + s.getOnlinenum());
			// allSumServerRealTimeDetailData.setAcitveUser(allSumServerRealTimeDetailData.getAcitveUser() + s.getAcitveUser());
			allSumServerRealTimeDetailData.setAcu(allSumServerRealTimeDetailData.getAcu() + s.getAcu());
			allSumServerRealTimeDetailData.setCapacity(allSumServerRealTimeDetailData.getCapacity() + s.getCapacity());
			// allSumServerRealTimeDetailData.setNewUser(allSumServerRealTimeDetailData.getNewUser() + s.getNewUser());
			allSumServerRealTimeDetailData.setPcu(allSumServerRealTimeDetailData.getPcu() + s.getPcu());
			allSumServerRealTimeDetailData.setPcuYesterday(allSumServerRealTimeDetailData.getPcuYesterday() + s.getPcuYesterday());
            allSumServerRealTimeDetailData.setDistinctNewUser(allSumServerRealTimeDetailData.getDistinctNewUser() + s.getDistinctNewUser());
            allSumServerRealTimeDetailData.setCashUser(allSumServerRealTimeDetailData.getCashUser() + s.getCashUser());
            allSumServerRealTimeDetailData.setCash(allSumServerRealTimeDetailData.getCash() + s.getCash());
		}
		List<Object[]> pcsActiveUser = dauByDayManager.getAllPCSDauRealTimeDatas(lookDate);
		if (pcsActiveUser != null && pcsActiveUser.size() > 0 && pcsActiveUser.get(0) != null) {
			allSumServerRealTimeDetailData.setAcitveUser(Long.parseLong(pcsActiveUser.get(0)[1].toString()));
		}
		List<Object[]> pcsNewUser = newUserByDayManager.getAllPCSNewUserRealTimeDatas(lookDate);
		if (pcsNewUser != null && pcsNewUser.size() > 0 && pcsNewUser.get(0) != null) {
			allSumServerRealTimeDetailData.setNewUser(Integer.parseInt(pcsNewUser.get(0)[1].toString()));
		}
        /*List<Object[]> pcsDistinctNewUser = distinctNewUserByDayManager.getAllPCSDistinctNewUserRealTimeDatas(lookDate);
        if (pcsDistinctNewUser != null && pcsDistinctNewUser.size() > 0 && pcsDistinctNewUser.get(0) != null) {
            allSumServerRealTimeDetailData.setDistinctNewUser(Integer.parseInt(pcsDistinctNewUser.get(0)[1].toString()));
        }*/

        String all2left = userSecondLeftByDayManager.getAllUserSecondLeftByConditions(yesterday, "0", "0", "0");
        if(all2left != null && all2left.contains("%")) {
            all2left = all2left.replaceAll("%", "");
            Float f = Float.valueOf(all2left);
            allSumServerRealTimeDetailData.setThe2Left(f / 100);
        }
        String all2macleft = userSecondLeftByDayManager.getAllMacSecondLeftByConditions(yesterday, "0", "0", "0");
        if(all2macleft != null && all2macleft.contains("%")) {
            all2macleft = all2macleft.replaceAll("%", "");
            Float f = Float.valueOf(all2macleft);
            allSumServerRealTimeDetailData.setMac2Left(f / 100);
        }
		allSumServerRealTimeDetailData.setCapacityUsedRadio(allSumServerRealTimeDetailData.getCapacity() == 0 ? 0 : (float)(allSumServerRealTimeDetailData.getOnlinenum() * 1.0 / allSumServerRealTimeDetailData.getCapacity()));
		allSumServerRealTimeDetailData.setMaxCapacityUsedRadioYesterday(allSumServerRealTimeDetailData.getCapacity() == 0 ? 0 : (float)(allSumServerRealTimeDetailData.getPcuYesterday() * 1.0 / allSumServerRealTimeDetailData.getCapacity()));
        allSumServerRealTimeDetailData.setActiveUserPayRadio(allSumServerRealTimeDetailData.getAcitveUser() == 0 ? 0 : (float)(allSumServerRealTimeDetailData.getCashUser() * 1.0 / allSumServerRealTimeDetailData.getAcitveUser()));
    }
	
	// 0="00:00"; 1="00:05";...;287="23:55"
	/*private String getMinuteStr(int key) {
		int hour = key / 12;
		int minute = key % 12 * 5;
		
		return ((hour < 10 ? "0" : "") + hour) + ":" + ((minute < 10 ? "0" : "") + minute);
	}*/
	
	// 项目整体实时在线
	public class OnlineRealTimeData {
		private String dateStr; // 日期串
		@ChartFlow(name = "分钟")
		private String minuteStr; // 分钟，每五分钟1个，一天288个
		@ChartSelect(name = "整体在线", key = 1)
		@ChartData1(name = "整体在线", key = 1, multiByFiled="dateStr")
		private long online; // 在线
		
		// 比较器
		public final Comparator<OnlineRealTimeData> comparator = new Comparator<OnlineRealTimeData>() {
			public int compare(OnlineRealTimeData s1, OnlineRealTimeData s2) {
				return s1.getMinuteStr().compareTo(s2.getMinuteStr());
			}
		};

		public String getMinuteStr() {
			return minuteStr;
		}

		public void setMinuteStr(String minuteStr) {
			this.minuteStr = minuteStr;
		}

		public long getOnline() {
			return online;
		}

		public void setOnline(long online) {
			this.online = online;
		}

		public String getDateStr() {
			return dateStr;
		}

		public void setDateStr(String dateStr) {
			this.dateStr = dateStr;
		}
	}
	
	// 服务器实时数据
	public class ServerRealTimeData {
		@ChartFlow(name="分钟")
		private String minuteStr; // 分钟，每五分钟1个，一天288个
		private String serverid; // 服务器ID
		private String serverName; // 服务器名称
		@ChartSelect(name="在线", key = 1)
		@ChartData1(name="在线", key = 1, multiByFiled="serverName")
		private long online; // 在线
		@ChartSelect(name="新增", key = 2)
		@ChartData1(name="新增", key = 2, multiByFiled="serverName")
		private int newUser; // 新增
		@ChartSelect(name="活跃", key = 3)
		@ChartData1(name="活跃", key = 3, multiByFiled="serverName")
		private int activeUser; // 活跃

		// 比较器
		public final Comparator<ServerRealTimeData> comparator = new Comparator<ServerRealTimeData>() {
			public int compare(ServerRealTimeData s1, ServerRealTimeData s2) {
				return s1.getMinuteStr().compareTo(s2.getMinuteStr());
			}
		};
		
		public String getMinuteStr() {
			return minuteStr;
		}

		public void setMinuteStr(String minuteStr) {
			this.minuteStr = minuteStr;
		}

		public String getServerid() {
			return serverid;
		}

		public void setServerid(String serverid) {
			this.serverid = serverid;
			this.serverName = BiPlatformManager.getServerNameById(serverid);
		}

		public long getOnline() {
			return online;
		}

		public void setOnline(long online) {
			this.online = online;
		}

		public int getNewUser() {
			return newUser;
		}

		public void setNewUser(int newUser) {
			this.newUser = newUser;
		}

		public int getActiveUser() {
			return activeUser;
		}

		public void setActiveUser(int activeUser) {
			this.activeUser = activeUser;
		}

		public String getServerName() {
			return serverName;
		}

		public void setServerName(String serverName) {
			this.serverName = serverName;
		}
	}
	
	// 服务器容量
	public class ServerCapacityData {
		@ChartFlow(name="日期")
		private String dateStr;
		private String serverid; // 服务器ID
		private String serverName; // 服务器名称
		@ChartSelect(name="使用率", key = 1)
		@ChartData1(name="使用率", key = 1, multiByFiled="serverName")
		private float capacityUsedRadio; // 使用率

		public final Comparator<ServerCapacityData> comparatorDate = new Comparator<ServerCapacityData>() {
			public int compare(ServerCapacityData s1, ServerCapacityData s2) {
				return s1.getDateStr().compareTo(s2.getDateStr());
			}
		};
		
		public String getDateStr() {
			return dateStr;
		}

		public void setDateStr(String dateStr) {
			this.dateStr = dateStr;
		}

		public String getServerid() {
			return serverid;
		}

		public void setServerid(String serverid) {
			this.serverid = serverid;
			this.serverName = BiPlatformManager.getServerNameById(serverid);
		}

		public float getCapacityUsedRadio() {
			return capacityUsedRadio;
		}

		public void setCapacityUsedRadio(float capacityUsedRadio) {
			this.capacityUsedRadio = capacityUsedRadio;
		}

		public String getServerName() {
			return serverName;
		}

		public void setServerName(String serverName) {
			this.serverName = serverName;
		}
	}
	
	// 分服详细数据
	public class ServerRealTimeDetailData {
		private String serverid; // 服务器ID
		private long onlinenum; // 在线人数
		private long pcu; // 最高同时在线人数
		private long pcuYesterday; // 最日PCU
		private long acu; // 平均同时在线人数
		private long newUser; // 新增用户
        private long distinctNewUser; // 新增用户
		private long acitveUser; // 活跃用户
		private long capacity; // 服务器容量
		private float capacityUsedRadio; // 服务器使用率：onlinenum/capacity
		private float maxCapacityUsedRadioYesterday; // 昨日最高使用率：昨日pcu/capacity
        private long cashUser;  // 付费帐号
        private long cash;  // 付费金额
        private float activeUserPayRadio;  // 活跃付费率
        private float the2Left;  // 次留
        private float mac2Left;  // mac次留

		public final Comparator<ServerRealTimeDetailData> comparatorServer = new Comparator<ServerRealTimeDetailData>() {
			public int compare(ServerRealTimeDetailData s1, ServerRealTimeDetailData s2) {
				return s1.getServerid().compareTo(s2.getServerid());
			}
		};

        public final Comparator<ServerRealTimeDetailData> comparatorOnline = new Comparator<ServerRealTimeDetailData>() {
            public int compare(ServerRealTimeDetailData s1, ServerRealTimeDetailData s2) {
                return (int)(s2.getOnlinenum() - s1.getOnlinenum());
            }
        };
		
		public String getServerid() {
			return serverid;
		}

		public void setServerid(String serverid) {
			this.serverid = serverid;
		}

		public long getOnlinenum() {
			return onlinenum;
		}

		public void setOnlinenum(long onlinenum) {
			this.onlinenum = onlinenum;
		}

		public long getPcu() {
			return pcu;
		}

		public void setPcu(long pcu) {
			this.pcu = pcu;
		}

		public long getAcu() {
			return acu;
		}

		public void setAcu(long acu) {
			this.acu = acu;
		}

		public long getNewUser() {
			return newUser;
		}

		public void setNewUser(long newUser) {
			this.newUser = newUser;
		}

		public long getAcitveUser() {
			return acitveUser;
		}

		public void setAcitveUser(long acitveUser) {
			this.acitveUser = acitveUser;
		}

		public long getCapacity() {
			return capacity;
		}

		public void setCapacity(long capacity) {
			this.capacity = capacity;
		}

		public float getCapacityUsedRadio() {
			return capacityUsedRadio;
		}

		public void setCapacityUsedRadio(float capacityUsedRadio) {
			this.capacityUsedRadio = capacityUsedRadio;
		}

		public float getMaxCapacityUsedRadioYesterday() {
			return maxCapacityUsedRadioYesterday;
		}

		public void setMaxCapacityUsedRadioYesterday(float maxCapacityUsedRadioYesterday) {
			this.maxCapacityUsedRadioYesterday = maxCapacityUsedRadioYesterday;
		}

		public long getPcuYesterday() {
			return pcuYesterday;
		}

		public void setPcuYesterday(long pcuYesterday) {
			this.pcuYesterday = pcuYesterday;
		}

        public long getDistinctNewUser() {
            return distinctNewUser;
        }

        public void setDistinctNewUser(long distinctNewUser) {
            this.distinctNewUser = distinctNewUser;
        }

        public long getCashUser() {
            return cashUser;
        }

        public void setCashUser(long cashUser) {
            this.cashUser = cashUser;
        }

        public long getCash() {
            return cash;
        }

        public void setCash(long cash) {
            this.cash = cash;
        }

        public float getActiveUserPayRadio() {
            return activeUserPayRadio;
        }

        public void setActiveUserPayRadio(float activeUserPayRadio) {
            this.activeUserPayRadio = activeUserPayRadio;
        }

        public float getThe2Left() {
            return the2Left;
        }

        public void setThe2Left(float the2Left) {
            this.the2Left = the2Left;
        }

        public float getMac2Left() {
            return mac2Left;
        }

        public void setMac2Left(float mac2Left) {
            this.mac2Left = mac2Left;
        }
    }
}
